import Vue from 'vue'
import App from './App'
//引入uview-ui
import uView from "uview-ui";
import store from './store'
Vue.use(uView);

Vue.config.productionTip = false

//配置基地址
uni.$u.http.setConfig((config) => {
  /* config 为默认全局配置*/
  config.baseURL = `https://api-hmugo-web.itheima.net/api/public/v1`; /* 根域名 */
  return config
})

//添加请求拦截器
uni.$u.http.interceptors.request.use((config) => {
  const token = store.state.user.token || uni.getStorageSync('token')
  console.log(config,'11',token);
  if(config.url.startsWith('/my/') && token){
    console.log('11');
    config.header.Authorization = token
  }
  uni.showLoading()
	return config
}, config => {
	return Promise.reject(config)
})

//添加响应拦截器
uni.$u.http.interceptors.response.use((response) => {
  uni.hideLoading()
	return response
}, (response) => {
	console.log(response)
	return Promise.reject(response)
})

import MyImage from '../src/components/my-image.vue'
Vue.component('my-image',MyImage)

App.mpType = 'app'

const app = new Vue({
  store,
  ...App
})
app.$mount()
